<?php
	require_once ("View/LoginView.php");
	require_once ("View/FileUploadView.php");
	require_once ("View/RegisterView.php");
	require_once ("View/NavigationView.php");
	require_once ("Controller/LoginController.php");
	require_once ("Controller/FileUploadController.php");
	require_once ("Controller/RegisterController.php");
	require_once ("Model/LoginHandler.php");
	require_once ("Model/FileUploadHandler.php");
	require_once ("Model/DBConnection.php");
	require_once ("Model/UserHandler.php");
	require_once ("../Log/Log.php");
	require_once ("../Log/LogView.php");
	require_once ("../Validation/Validate.php");
	require_once ("config.php");

	session_start();
	$aDBConnection = new DBConnection();
	$aDBConnection->Connect();
	
	$aLogView = new LogView();
	$aLoginView = new LoginView();
	$aFileUploadView = new FileUploadView();
	$aRegisterView = new RegisterView();
	$aNavigationView = new NavigationView();
	$aLoginController = new LoginController();
	$aFileUploadController = new FileUploadController();
	$aRegisterController = new RegisterController();
	$aFileUploadHandler = new FileUploadHandler();
	$aUserHandler = new UserHandler($aDBConnection);
	$aLoginHandler = new LoginHandler($aUserHandler);
	
	$title = "Login";
	
	if($aNavigationView->IsRegisterControllerActive() == true){
		$body = $aRegisterController->DoControll($aRegisterView,$aRegisterHandler);
		$body .= $aNavigationView->DoBackToLoginLink();
	}
	else{
		$body = "<div>" . $aLoginController->DoControll($aLoginView, $aLoginHandler);
		if ($aLoginHandler->IsLoggedIn()){
			$body .= "You are logged in";
		}
		else{
			$body .= "You are not logged in";
			$body .= $aNavigationView->DoRegisterLink();
		}
	
		$body .='</div><br/><div>' . $aFileUploadController->DoControll($aFileUploadView, 
																  	   $aFileUploadHandler, 	
																  	   $aLoginHandler->IsLoggedIn()) . "</div>";
	}
	$aDBConnection->Close();
	//$aLogView->ShowMessages();
?>
    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="se">

    <head>
	    <title><?php echo "$title"?></title>
	    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    </head>

    <body>
    	<?php echo "$body"?>
    </body>
    
</html>